package com.lc1993929.dubbo.boot.health;

import com.alibaba.dubbo.rpc.service.EchoService;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;

/**
 * Created by jianglin on 2017/3/31
 */
public class DubboServiceHealthIndicator extends AbstractHealthIndicator {

    private EchoService echoService;

    public DubboServiceHealthIndicator(EchoService echoService) {
        this.echoService = echoService;
    }

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        if (echoService == null) {
            builder.up();
            return;
        }
        String data = "This is a health message at time :" + System.currentTimeMillis();
        try {
            echoService.$echo(data);
        } catch (Exception e) {
            throw e;
        }
        builder.up().withDetail("msg", data);
    }
}
